package com.gitee.tanmingjian.httptunnel.core.util;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class IOUtils {

    public static String toString(final InputStream input, final String encoding) throws IOException {
        try (ByteArrayOutputStream result = new ByteArrayOutputStream()) {
            byte[] buffer = new byte[1024];
            for (int l; (l = input.read(buffer)) != -1; ) {
                result.write(buffer, 0, l);
            }
            return result.toString(encoding);
        }
    }

}
